package controllers

import (
	"gdshop-back-end-go/common/libs/token"
	"gdshop-back-end-go/common/request/AddressReq"
	"gdshop-back-end-go/common/response"
	"gdshop-back-end-go/service-member/AddressService"
	"github.com/gogf/gf/net/ghttp"
)

type AddressController struct {
	*BaseController
}

func (c *AddressController) Init(r *ghttp.Request) *response.JsonResponse {
	memberId = token.GetLoginMemberId(r)
	if memberId < 1 {
		return response.FailByRequestMessage(r, "获取会员ID失败")
	}
	return response.SuccessByRequest(r)
}

// 地址列表
func (c *AddressController) List(r *ghttp.Request) *response.JsonResponse {
	var parames *AddressReq.List
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = memberId
	return AddressService.List(r.GetCtx(), parames)
}

// 地址详情
func (c *AddressController) Details(r *ghttp.Request) *response.JsonResponse {
	var parames *AddressReq.Details
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = memberId
	return AddressService.Details(r.GetCtx(), parames)
}
func (c *AddressController) Add(r *ghttp.Request) *response.JsonResponse {
	var parames *AddressReq.Save
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = memberId
	return AddressService.Add(r.GetCtx(), parames)
}
func (c *AddressController) Save(r *ghttp.Request) *response.JsonResponse {
	var parames *AddressReq.Save
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = memberId
	return AddressService.Save(r.GetCtx(), parames)
}
func (c *AddressController) Del(r *ghttp.Request) *response.JsonResponse {
	var parames *AddressReq.Del
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.MemberId = memberId
	return AddressService.Del(r.GetCtx(), parames)
}
